#ifndef SIMPLEADAPTER_H
#define SIMPLEADAPTER_H


#include <QObject>
#include <QDBusAbstractAdaptor>
#include <QDBusConnection>
#include <QDBusInterface>

#include "simple.h"

class SimpleAdapter : public QDBusAbstractAdaptor
{
Q_OBJECT

public:
    SimpleAdapter(Simple *s):
        QDBusAbstractAdaptor(s), service(s)
    {
        connect(s, &Simple::StateChanged, this, &SimpleAdapter::StateChanged);
    }

public Q_SLOTS:
    QString SayHello() {
        return service->SayHello();
    }

signals:
    void StateChanged(QString info);

protected:
    Simple *service;

};

class Simple001: public SimpleAdapter
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "Simples.Example001")

public:
    Simple001(Simple *s) :
        SimpleAdapter(s)
    {
        auto connection = QDBusConnection::sessionBus();
        auto result = connection.registerObject("/Simples/Example001", service);
        if (!result) {
        }
    }

public Q_SLOTS:
    int Add(int a, int b) {
        return service->Add1(a, b);
    }
};


class Simple002: public SimpleAdapter
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "Simples.Example002")

public:
    Simple002(Simple *s) :
        SimpleAdapter(s)
    {
        auto connection = QDBusConnection::sessionBus();
        auto result = connection.registerObject("/Simples/Example002", service);
        if (!result) {
        }
    }

public Q_SLOTS:
    int Add(int a, int b) {
        return service->Add2(a, b);
    }

};


#endif // SIMPLEADAPTER_H
